package me.ingxin.android.router.base

import android.os.Bundle
import android.os.Parcelable
import android.util.SparseArray
import java.io.Serializable

/**
 * Created by ingxin on 2022/4/18
 */
@Suppress("UNCHECKED_CAST")
abstract class DataExtras<T> {

    @JvmField
    val extra: Bundle = Bundle()

    fun putBundle(key: String, value: Bundle?): T {
        extra.putBundle(key, value)
        return this as T
    }

    fun putBoolean(key: String, value: Boolean): T {
        extra.putBoolean(key, value)
        return this as T
    }

    fun putByte(key: String, value: Byte): T {
        extra.putByte(key, value)
        return this as T
    }

    fun putChar(key: String, value: Char): T {
        extra.putChar(key, value)
        return this as T
    }

    fun putShort(key: String, value: Short): T {
        extra.putShort(key, value)
        return this as T
    }

    fun putInt(key: String, value: Int): T {
        extra.putInt(key, value)
        return this as T
    }

    fun putLong(key: String, value: Long): T {
        extra.putLong(key, value)
        return this as T
    }

    fun putFloat(key: String, value: Float): T {
        extra.putFloat(key, value)
        return this as T
    }

    fun putDouble(key: String, value: Double): T {
        extra.putDouble(key, value)
        return this as T
    }

    fun putString(key: String, value: String?): T {
        extra.putString(key, value)
        return this as T
    }

    fun putCharSequence(key: String, value: CharSequence?): T {
        extra.putCharSequence(key, value)
        return this as T
    }

    fun putSerializable(key: String, value: Serializable?): T {
        extra.putSerializable(key, value)
        return this as T
    }

    fun putParcelable(key: String, value: Parcelable?): T {
        extra.putParcelable(key, value)
        return this as T
    }

    fun putBooleanArray(key: String, value: BooleanArray?): T {
        extra.putBooleanArray(key, value)
        return this as T
    }

    fun putByteArray(key: String, value: ByteArray): T {
        extra.putByteArray(key, value)
        return this as T
    }

    fun putShortArray(key: String, value: ShortArray?): T {
        extra.putShortArray(key, value)
        return this as T
    }

    fun putCharArray(key: String, value: CharArray?): T {
        extra.putCharArray(key, value)
        return this as T
    }

    fun putIntArray(key: String, value: IntArray?): T {
        extra.putIntArray(key, value)
        return this as T
    }

    fun putLongArray(key: String, value: LongArray?): T {
        extra.putLongArray(key, value)
        return this as T
    }

    fun putFloatArray(key: String, value: FloatArray?): T {
        extra.putFloatArray(key, value)
        return this as T
    }

    fun putDoubleArray(key: String, value: DoubleArray?): T {
        extra.putDoubleArray(key, value)
        return this as T
    }

    fun putStringArray(key: String, value: Array<String>?): T {
        extra.putStringArray(key, value)
        return this as T
    }

    fun putCharSequenceArray(key: String, value: Array<CharSequence>?): T {
        extra.putCharSequenceArray(key, value)
        return this as T
    }

    fun putParcelableArray(key: String, value: Array<Parcelable>?): T {
        extra.putParcelableArray(key, value)
        return this as T
    }

    fun putSparseParcelableArray(key: String, value: SparseArray<out Parcelable>?): T {
        extra.putSparseParcelableArray(key, value)
        return this as T
    }

    fun putIntegerArrayList(key: String, value: ArrayList<Int>?): T {
        extra.putIntegerArrayList(key, value)
        return this as T
    }

    fun putStringArrayList(key: String, value: ArrayList<String>?): T {
        extra.putStringArrayList(key, value)
        return this as T
    }

    fun putCharSequenceArrayList(key: String, value: ArrayList<CharSequence>?): T {
        extra.putCharSequenceArrayList(key, value)
        return this as T
    }

    fun putParcelableArrayList(key: String, value: ArrayList<out Parcelable>?): T {
        extra.putParcelableArrayList(key, value)
        return this as T
    }

    fun putExtras(bundle: Bundle): T {
        extra.putAll(bundle)
        return this as T
    }

    fun getBoolean(key: String, defaultValue: Boolean = false): Boolean {
        return extra.getBoolean(key, defaultValue)
    }

    fun getByte(key: String, defaultValue: Byte = 0): Byte {
        return extra.getByte(key, defaultValue)
    }

    fun getChar(key: String, defaultValue: Char = 0.toChar()): Char {
        return extra.getChar(key, defaultValue)
    }

    fun getShort(key: String, defaultValue: Short = 0.toShort()): Short {
        return extra.getShort(key, defaultValue)
    }

    fun getInt(key: String, defaultValue: Int = 0): Int {
        return extra.getInt(key, defaultValue)
    }

    fun getLong(key: String, defaultValue: Long = 0): Long {
        return extra.getLong(key, defaultValue)
    }

    fun getFloat(key: String, defaultValue: Float = 0f): Float {
        return extra.getFloat(key, defaultValue)
    }

    fun getDouble(key: String, defaultValue: Double = 0.0): Double {
        return extra.getDouble(key, defaultValue)
    }

    fun getString(key: String, defaultValue: String? = null): String? {
        return extra.getString(key, defaultValue)
    }

    fun getBundle(key: String): Bundle? {
        return extra.getBundle(key)
    }

    fun getCharSequence(key: String, defaultValue: CharSequence? = null): CharSequence? {
        return extra.getCharSequence(key, defaultValue)
    }

    fun <M : Parcelable> getParcelable(key: String): M? {
        return extra.getParcelable(key)
    }

    fun getSerializable(key: String): Serializable? {
        return extra.getSerializable(key)
    }

    fun getStringArray(key: String): Array<String>? {
        return extra.getStringArray(key)
    }

    fun getBooleanArray(key: String): BooleanArray? {
        return extra.getBooleanArray(key)
    }

    fun getShortArray(key: String): ShortArray? {
        return extra.getShortArray(key)
    }

    fun getIntArray(key: String): IntArray? {
        return extra.getIntArray(key)
    }

    fun getLongArray(key: String): LongArray? {
        return extra.getLongArray(key)
    }

    fun getByteArray(key: String): ByteArray? {
        return extra.getByteArray(key)
    }

    fun getCharArray(key: String): CharArray? {
        return extra.getCharArray(key)
    }

    fun getFloatArray(key: String): FloatArray? {
        return extra.getFloatArray(key)
    }

    fun getDoubleArray(key: String): DoubleArray? {
        return extra.getDoubleArray(key)
    }

    fun getCharSequenceArray(key: String): Array<CharSequence>? {
        return extra.getCharSequenceArray(key)
    }

    fun getParcelableArray(key: String): Array<Parcelable>? {
        return extra.getParcelableArray(key)
    }

    fun <M : Parcelable?> getParcelableArrayList(key: String): ArrayList<M>? {
        return extra.getParcelableArrayList(key)
    }

    fun getIntegerArrayList(key: String): ArrayList<Int>? {
        return extra.getIntegerArrayList(key)
    }

    fun getStringArrayList(key: String): ArrayList<String>? {
        return extra.getStringArrayList(key)
    }

    fun getCharSequenceArrayList(key: String): ArrayList<CharSequence>? {
        return extra.getCharSequenceArrayList(key)
    }

    fun <M : Parcelable> getSparseParcelableArray(key: String): SparseArray<M>? {
        return extra.getSparseParcelableArray(key)
    }

}